package com.qifenqian.turbot.module.ui.restaurant

import android.content.Context
import android.content.Intent
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseActivity
import com.qifenqian.turbot.module.contract.RestaurantContract
import com.qifenqian.turbot.module.presenter.RestaurantPresenter
import kotlinx.android.synthetic.main.activity_restaurant_introduction.*
import org.jetbrains.anko.toast

/**
 * @author H
 * @createDate 2018/12/26 11:56
 * @description 餐厅介绍界面
 * @see
 * @since
 */
private const val CURRENT_INTRODUCTION = "currentIntroduction"

class RestaurantIntroductionActivity : BaseActivity<RestaurantPresenter, RestaurantContract.View>(), RestaurantContract.View {

    override fun bindLayoutId(): Int {
        return R.layout.activity_restaurant_introduction
    }

    override fun bindPresenter(): RestaurantPresenter {
        return RestaurantPresenter(this, this)
    }

    override fun initial() {
        val currentIntroduction = intent.getStringExtra(CURRENT_INTRODUCTION)
        et_restaurant_introduction_edit.setText(currentIntroduction)
        btn_restaurant_introduction_next.setOnClickListener {
            if (et_restaurant_introduction_edit.text.toString().isBlank()) {
                toast("请输入餐厅介绍")
                return@setOnClickListener
            }
            mPresenter!!.changeRestaurantIntroduction(et_restaurant_introduction_edit.text.toString())
        }
    }

    override fun changeRestaurantIntroductionResult(isSuccess: Boolean, code: Int, msg: String?) {
        if (isSuccess) {
            finish()
        }
        toast(msg!!)
    }

    companion object {
        fun startThis(context: Context, currentIntroduction: String?) {
            val intent = Intent(context, RestaurantIntroductionActivity::class.java)
            intent.putExtra(CURRENT_INTRODUCTION, currentIntroduction)
            context.startActivity(intent)
        }
    }

}
